package gameobject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.swing.ImageIcon;

import engine.JLeibniz;

/**
 * A room has a name and a description. Genius, I know.
 * 
 * @author Simon Dehne
 *
 */
public class Room {
	
	private String name;
	private String description;
	// path to the room's image file
	private String image;
	
	// List of items that are in the room.
	private Map<String, Object> items;
	
	// List of exits
	private LinkedList<Exit> exits;

	
	/**
	 * Constructor. You know the drill.
	 * @throws IOException 
	 */
	public Room(String nm, String d) throws IOException {
		
		name = nm;
		description = d;
		items = new HashMap<String, Object>();
		exits = new LinkedList<Exit>();
		image = "res/rooms/"+name+".png";
		
		ImageIcon imageIc = new ImageIcon(image);
		
		// If no image for this room exits, throw an error
		if(imageIc.getIconHeight() == -1) {			
			if(JLeibniz.isDebug) JLeibniz.outWriter.write("No image icon found for room "+name+"! Terminating game.");
			System.exit(-1);
		}

	}
	
	/**
	 * Getter for the name.
	 * 
	 * @return	The name.
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Gets a description of the room, as well as all items in it.
	 * 
	 * @return	Description, items and exits of the room.
	 */	
	String getDescription() {		
			return description;		
	}

	/**
	 * Getter for the items in the room.
	 * 
	 * @return	Map of the items in the room.
	 */
	public Map<String, Object> getItems() {
		return items;
	}
	
	public LinkedList<Exit> getExits() {
		return exits;
	}
	
	/**
	 * Getter for the image path.
	 * 
	 * @return	The image path.
	 */
	public String getImagePath() {
		return image;
	}
	
	/**
	 * Setter for the name of the room.
	 * 
	 * @param nm	The name of the room.
	 */
	void setName(String nm) {
		name = nm;
	}
	
	/**
	 * Setter for the description of the room.
	 * 
	 * @param d	The description of the room.
	 */
	void setDescription(String d) {
		description = d;
	}
	
	/**
	 * Adds an item to this room.
	 * 
	 * @param obj	The item to be added.
	 */
	void addItem(Object obj) {
		items.put(obj.getName(), obj);
	}
	
	public void addExit(Exit exit) {
		exits.add(exit);
	}
	
	void setImagePath(String i) {
		this.image = i;
	}

}
